import {USER_LOGIN, USER_LOGOUT, LOGIN_START, LOGIN_SUCCESS, LOGIN_FAIL} from "../constant/ReduxConstant";
import {request} from "../utils";

export function login(payload) {
    let {phone, password} = payload
    return async dispatch => {
        dispatch({type: LOGIN_START});
        let res = await request.get(ApiConfig.AUTH.LOGIN_BY_PHONE, {phone, password})
        if (res) {
            dispatch({
                type: LOGIN_SUCCESS,
                payload: res
            })
        } else {
            dispatch({type: LOGIN_FAIL})
        }
    }
}

export function logout() {
    return {type: USER_LOGOUT}
}
